# Contributor: omni <omni+alpine@hack.org>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=py3-adblock
_pkgname=python-adblock
pkgver=0.6.0
pkgrel=5
pkgdesc="Python wrapper for Brave's adblocking library"
url="https://github.com/ArniDagur/python-adblock"
arch="all"
arch="$arch !ppc64le" # limited by ring crate
license="Apache-2.0 MIT"
makedepends="
	cargo
	openssl-dev
	py3-gpep517
	py3-installer
	py3-maturin
	py3-setuptools
	"
checkdepends="
	py3-pytest-xdist
	py3-toml
	"
subpackages="$pkgname-doc:doc $pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/ArniDagur/python-adblock/archive/refs/tags/$pkgver.tar.gz
	fix-build-pep517.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"
options="net" # cargo

prepare() {
	default_prepare

	cargo fetch --locked
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--config-json '{"build-args": "--frozen --all-features"}' \
		--output-fd 3 3>&1 >&2}
}

check() {
	local python_path="$(python3 -c \
		'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
	mkdir -vp testdir
	export PYTHONPATH="testdir$python_path:$PYTHONPATH"

	python3 -m installer -d testdir \
		.dist/*.whl
	pytest -n auto -k 'not test_version_numbers_all_same and not test_required_python_version'
}

package() {
	install -Dm755 target/release/libadblock.so -t "$pkgdir/usr/lib"
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	install -Dm0644 LICENSE-APACHE "$pkgdir/usr/share/licenses/$pkgname/LICENSE-APACHE"
	install -Dm0644 LICENSE-MIT "$pkgdir/usr/share/licenses/$pkgname/LICENSE-MIT"
}

sha512sums="
c313483414539594c8836d83930e089ffdaba2e3ff032e4365428440ca357f84dbe82896873c93f5265ac05760006dac2b214728a7b16ab7f6bac4e30ff0a39f  py3-adblock-0.6.0.tar.gz
698d96ffb626bc7f919cdb30027ce7cefcc7dcdbb61eeebefca1264cba334c9125d0c7a40f63a139c0f436ef13f070f8c1ce7c893a28116ad7b5c6f76fbf95d5  fix-build-pep517.patch
"
